import Mock from "mockjs";
//出售中商品列表
const data = Mock.mock({
  data: [
    {
      id: "@id",
      label: "每日优先",
      "children|100": [
        {
          "id|+13": 1, //id
          img: "@image(50x50,@color)", //图
          title: "@ctitle(7,20)", //名称
          "price|1-9999": 1 + 0.0, //售价
          "sale|1-500": 1, //销量
          "num|0-10000": 1, //库存
          "flag|1": [true, false], //状态
          "sort|1-100": 1, //排序
          time: "@datetime"
        }
      ]
    },
    {
      id: "@id",
      label: "精选推荐",
      "children|100": [
        {
          "id|1-200": 1, //id
          img: "@image(50x50,@color)", //图
          title: "@ctitle(7,20)", //名称
          "price|1-9999": 1 + 0.0, //售价
          "sale|1-500": 1, //销量
          "num|0-10000": 1, //库存
          "flag|1": [true, false], //状态
          "sort|1-100": 1, //排序
          time: "@datetime"
        }
      ]
    },
    {
      id: "@id",
      label: "换季大促",
      "children|100": [
        {
          "id|1-200": 1, //id
          img: "@image(50x50,@color)", //图AAa嗄,L
          title: "@ctitle(7,20)", //名称
          "price|1-9999": 1 + 0.0, //售价
          "sale|1-500": 1, //销量
          "num|0-10000": 1, //库存
          "flag|1": [true, false], //状态
          "sort|1-100": 1, //排序
          time: "@datetime"
        }
      ]
    },
    {
      id: "@id",
      label: "时尚家居",
      "children|100": [
        {
          "id|1-200": 1, //id
          img: "@image(50x50,@color)", //图
          title: "@ctitle(7,20)", //名称
          "price|1-9999": 1 + 0.0, //售价
          "sale|1-500": 1, //销量
          "num|0-10000": 1, //库存
          "flag|1": [true, false], //状态
          "sort|1-100": 1, //排序
          time: "@datetime"
        }
      ]
    },
    {
      id: "@id",
      label: "数码商品",
      "children|100": [
        {
          "id|1-200": 1, //id
          img: "@image(50x50,@color)", //图
          title: "@ctitle(7,20)", //名称
          "price|1-9999": 1 + 0.0, //售价
          "sale|1-500": 1, //销量
          "num|0-10000": 1, //库存
          "flag|1": [true, false], //状态
          "sort|1-100": 1, //排序
          time: "@datetime"
        }
      ]
    },
    {
      id: "@id",
      label: "服装美女",
      "children|100": [
        {
          "id|1-200": 1, //id
          img: "@image(50x50,@color)", //图
          title: "@ctitle(7,20)", //名称
          "price|1-9999": 1 + 0.0, //售价
          "sale|1-500": 1, //销量
          "num|0-10000": 1, //库存
          "flag|1": [true, false], //状态
          "sort|1-100": 1, //排序
          time: "@datetime"
        }
      ]
    },
    {
      id: "@id",
      label: "手机",
      "children|100": [
        {
          "id|1-200": 1, //id
          img: "@image(50x50,@color)", //图
          title: "@ctitle(7,20)", //名称
          "price|1-9999": 1 + 0.0, //售价
          "sale|1-500": 1, //销量
          "num|0-10000": 1, //库存
          "flag|1": [true, false], //状态
          "sort|1-100": 1, //排序
          time: "@datetime"
        }
      ]
    },
    {
      id: "@id",
      label: "电脑",
      "children|100": [
        {
          "id|1-200": 1, //id
          img: "@image(50x50,@color)", //图
          title: "@ctitle(7,20)", //名称
          "price|1-9999": 1 + 0.0, //售价
          "sale|1-500": 1, //销量
          "num|0-10000": 1, //库存
          "flag|1": [true, false], //状态
          "sort|1-100": 1, //排序
          time: "@datetime"
        }
      ]
    },
    {
      id: "@id",
      label: "照相机",
      "children|100": [
        {
          "id|1-200": 1, //id
          img: "@image(50x50,@color)", //图
          title: "@ctitle(7,20)", //名称
          "price|1-9999": 1 + 0.0, //售价
          "sale|1-500": 1, //销量
          "num|0-10000": 1, //库存
          "flag|1": [true, false], //状态
          "sort|1-100": 1, //排序
          time: "@datetime"
        }
      ]
    }
  ]
});

Mock.mock("/getShopList", "post", req => {
  const { pageSize, pageIndex, active } = JSON.parse(req.body);
  console.log(data.data[active].children);
  if (pageSize && pageIndex && (active || active === 0)) {
    if (data.data[active].children) {
      let dataList = data.data[active].children.slice(
        (pageIndex - 1) * pageSize,
        pageSize * pageIndex
      );
      console.log("dataList", dataList);
      return {
        code: 20000,
        data: data,
        dataList: dataList
      };
    }
  }
});
